home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / print.c < prev    next >
C/C++ Source or Header  |  1993-05-21  |  18KB  |  563 lines

  1. /*    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  2.  
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7.  
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with this software; see the file COPYING.  If not, write to
  15. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include "display.h"
  20. #include "font.h"
  21. #include "global.h"
  22. #include "cmd.h"
  23. #include "io-generic.h"
  24. #include "io-abstract.h"
  25. #include "print.h"
  26.  
  27.  
  28.  
  29. #ifdef __STDC__
  30. static void 
  31. put_eps_header (struct display *dpy, float scale, float wid, float hgt, FILE *fp)
  32. #else
  33. static void 
  34. put_eps_header (dpy, scale, wid, hgt, fp)
  35.      struct display *dpy;
  36.      float scale;
  37.      float wid;
  38.      float hgt;
  39.      FILE *fp;
  40. #endif
  41. {
  42.   int dpy_wid = display_width (dpy);
  43.   int dpy_hgt = display_height (dpy);
  44.   struct font_memo *fm;
  45.   fputs ("%!PS-Adobe-2.0 EPSF-2.0\n", fp);
  46.   fprintf (fp, "%%%%BoundingBox: %d %d %d %d\n",
  47.        0, 0,
  48.        (int) ((float) dpy_wid * scale),
  49.        (int) ((float) (dpy_hgt + 1) * scale));
  50.   fputs ("%%Creator: oleo\n", fp);
  51.   fputs ("%%DocumentFonts: Times-Roman", fp);
  52.   for (fm = font_list; fm; fm = fm->next)
  53.     fprintf (fp, " %s", fm->names->ps_name);
  54.   fputc ('\n', fp);
  55.   {
  56.     time_t the_record_of_the_time = time (0);
  57.     fprintf (fp, "%%%%CreationDate: %s\n", ctime (&the_record_of_the_time));
  58.   }
  59.   fputs ("%%EndComments\n", fp);
  60. }
  61.  
  62. #ifdef __STDC__
  63. void 
  64. put_ps_string (char *str, FILE *fp)
  65. #else
  66. void 
  67. put_ps_string (str, fp)
  68.      char *str;
  69.      FILE *fp;
  70. #endif
  71. {
  72.   fputc ('(', fp);
  73.   while (*str)
  74.     {
  75.       if (*str == ')')
  76.     fputs ("\\)", fp);
  77.       else if (*str == '(')
  78.     fputs ("\\(", fp);
  79.       else
  80.     fputc (*str, fp);
  81.       ++str;
  82.     }
  83.   fputc (')', fp);
  84. }
  85.  
  86. #ifdef __STDC__
  87. void 
  88. psprint_region (FILE * fp, struct rng * rng,
  89.         float wid, float hgt, char * font)
  90. #else
  91. void 
  92. psprint_region (fp, rng, wid, hgt, font)
  93.      FILE *fp;
  94.      struct rng *rng;
  95.      float wid, hgt;
  96.      char * font;
  97. #endif
  98. {
  99.   struct display dpy;
  100.   int rows = rng->hr - rng->lr + 1;
  101.   int cols = rng->hc - rng->lc + 1;
  102.   int dpy_wid;
  103.   int dpy_hgt;
  104.   float scale;
  105.  
  106.   build_unscaled_display (&dpy, rng, 0, 0);
  107.   dpy_wid = display_width (&dpy);
  108.   dpy_hgt = display_height (&dpy);
  109.   scale = wid / (float) dpy_wid;
  110.   if (scale * dpy_hgt > hgt)
  111.     scale = hgt / (float) dpy_hgt;
  112.  
  113.   put_eps_header (&dpy, scale, wid, hgt, fp);
  114.   fprintf (fp, "/min { 2 copy lt { pop } if } def\n");
  115.   fprintf (fp, "/max { 2 copy lt { exch pop } if } def\n");
  116.   fprintf (fp, "/fed { exch def } def\n");
  117.   fprintf (fp, "/gget { cvi get } def\n");
  118.   fprintf (fp, "%% Some basic facts about the region being printed. \n");
  119.   fprintf (fp, "/CharsWide %d def\n", dpy_wid);
  120.   fprintf (fp, "/CharsTall %d def\n", dpy_hgt);
  121.   fprintf (fp, "/Cols       %d def\n", cols);
  122.   fprintf (fp, "/Rows      %d def\n", rows);
  123.   fprintf (fp, "%% The scale is just the point size of the default font. \n");
  124.   fprintf (fp, "%% The value here is just an initial approximation.  The real value\n");
  125.   fprintf (fp, "%% is computed below.\n");
  126.   fprintf (fp, "/Scale     %f def\n", scale);
  127.   fprintf (fp, "/PointsWide CharsWide Scale mul def\n");
  128.   fprintf (fp, "/PointsTall CharsTall Scale mul def\n");
  129.   fprintf (fp, "\n");
  130.   fprintf (fp, "%% font setup\n");
  131.   fprintf (fp, "/pair-sub \n");
  132.   fprintf (fp, "{\n");
  133.   fprintf (fp, "  3 -1 roll exch sub 3 1 roll sub exch\n");
  134.   fprintf (fp, "} def\n");
  135.   fprintf (fp, "/font-box\n");
  136.   fprintf (fp, "{\n");
  137.   fprintf (fp, "  dup /FontBBox get /font-box-box fed\n");
  138.   fprintf (fp, "  /FontMatrix get /font-box-matrix fed\n");
  139.   fprintf (fp, "  font-box-box font-box-matrix transform\n");
  140.   fprintf (fp, "  4 2 roll font-box-matrix transform\n");
  141.   fprintf (fp, "  pair-sub  \n");
  142.   fprintf (fp, "} def\n");
  143.   fprintf (fp, "/DefaultFontName /%s def\n", default_font()->names->ps_name);
  144.   fprintf (fp, "/BasicDefaultFont DefaultFontName findfont def\n");
  145.   fprintf (fp, "/DefaultFontSize Scale round def\n");
  146.   fprintf (fp, "/SizeDir 1 def\n");
  147.   fprintf (fp, "{ \n");
  148.   fprintf (fp, "  DefaultFontSize 4 le { exit } if\n");
  149.   fprintf (fp, "  /DefaultFont BasicDefaultFont DefaultFontSize scalefont def\n");
  150.   fprintf (fp, "  DefaultFont setfont \n");
  151.   fprintf (fp, "  DefaultFont font-box\n");
  152.   fprintf (fp, "  Scale le exch Scale le and not\n");
  153.   fprintf (fp, "  { /SizeDir -1 def } { SizeDir 0 le { exit } if } ifelse\n");
  154.   fprintf (fp, "  /DefaultFontSize DefaultFontSize SizeDir add def\n");
  155.   fprintf (fp, "} loop\n");
  156.   fprintf (fp, "/DefaultFontSize DefaultFontSize def\n");
  157.   fprintf (fp, "/DefaultFont BasicDefaultFont DefaultFontSize scalefont def\n");
  158.   fprintf (fp, "/Scale DefaultFontSize def\n");
  159.   fprintf (fp, "\n");
  160.   fprintf (fp, "DefaultFont font-box\n");
  161.   fprintf (fp, "/Scaleh fed\n");
  162.   fprintf (fp, "/Scalew fed\n");
  163.   fprintf (fp, "\n");
  164.   fprintf (fp, "/CellsUsed Rows Cols mul array def\n");
  165.   fprintf (fp, "0 1 Rows Cols mul 1 sub { CellsUsed exch false put } for\n");
  166.   fprintf (fp, "\n");
  167.   fprintf (fp, "/checkused   %% r c -- bool\n");
  168.   fprintf (fp, "{\n");
  169.   fprintf (fp, "  exch Cols mul add CellsUsed exch gget\n");
  170.   fprintf (fp, "} def\n");
  171.   fprintf (fp, "\n");
  172.   fprintf (fp, "/setused   %% r c -- \n");
  173.   fprintf (fp, "{\n");
  174.   fprintf (fp, "  exch Cols mul add CellsUsed exch true put\n");
  175.   fprintf (fp, "} def\n");
  176.   fprintf (fp, "\n");
  177.   {
  178.     int ri, ci;
  179.     for (ri = 0; ri < rows; ++ri)
  180.       for (ci = 0; ci < cols; ++ci)
  181.     {
  182.       struct cell_display * cd = dpy.cells + ri * cols + ci;
  183.       if (cd->unclipped)
  184.         fprintf (fp, "%d %d setused\n", ri, ci);
  185.     }
  186.     fprintf (fp, "/Rowy [ ");
  187.     for (ri = 0; ri < rows; ++ri)
  188.       fprintf (fp, "%d ", dpy.rowy[ri]);
  189.     fprintf (fp, "] def\n/Colx [ ");
  190.     for (ci = 0; ci < cols; ++ci)
  191.       fprintf (fp, "%d ", dpy.colx[ci]);
  192.     fprintf (fp, "] def\n");
  193.     fprintf (fp, "/Heights [ ");
  194.     for (ri = 0; ri < rows; ++ri)
  195.       fprintf (fp, "%d ", dpy.heights[ri]);
  196.     fprintf (fp, "] def\n/Widths [ ");
  197.     for (ci = 0; ci < cols; ++ci)
  198.       fprintf (fp, "%d ", dpy.widths[ci]);
  199.     fprintf (fp, "] def\n");
  200.   }
  201.   fprintf (fp, "\n");
  202.   fprintf (fp, "/to-oleo-matrix\n");
  203.   fprintf (fp, "    0 PointsTall neg matrix translate \n");
  204.   fprintf (fp, "    1 Scalew div 1 Scaleh div neg matrix scale\n");
  205.   fprintf (fp, " matrix concatmatrix def\n");
  206.   fprintf (fp, "\n");
  207.   fprintf (fp, "/from-oleo-matrix to-oleo-matrix matrix invertmatrix def\n");
  208.   fprintf (fp, "\n");
  209.   fprintf (fp, "/rc-to-oleo-xy { Colx exch gget exch Rowy exch gget } def\n");
  210.   fprintf (fp, "/rc-to-oleo-wh { Widths exch gget exch Heights exch gget } def\n");
  211.   fprintf (fp, "/oleo-xy-to-ps { from-oleo-matrix transform } def\n");
  212.   fprintf (fp, "/rc-to-xy { rc-to-oleo-xy oleo-xy-to-ps } def\n");
  213.   fprintf (fp, "/rc-to-wh { rc-to-oleo-wh Scaleh mul exch Scalew mul exch } def\n");
  214.   fprintf (fp, "/oleo-box-to-ps\n");
  215.   fprintf (fp, "{ \n");
  216.   fprintf (fp, "  dup dup 0 gget exch 1 gget oleo-xy-to-ps\n");
  217.   fprintf (fp, "  3 -1 roll dup dup 2 gget exch 3 gget oleo-xy-to-ps\n");
  218.   fprintf (fp, "  3 -1 roll astore\n");
  219.   fprintf (fp, "} def\n");
  220.   fprintf (fp, "\n");
  221.   fprintf (fp, "\n");
  222.   fprintf (fp, "/cell-goal   %% string just r c -- [x y x' y']\n");
  223.   fprintf (fp, "{\n");
  224.   fprintf (fp, "  3 index stringwidth pop /cell-goal-w exch def\n");
  225.   fprintf (fp, "  /cell-goal-h DefaultFontSize 2 add def\n");
  226.   fprintf (fp, "  2 copy rc-to-xy   %% str j r c xcel ycel\n");
  227.   fprintf (fp, "  5 -1 roll dup 0 lt \n");
  228.   fprintf (fp, "  { pop }  %% str r c xstr ycel\n");
  229.   fprintf (fp, "  { 0 eq         %% str r c xcel ycel bool\n");
  230.   fprintf (fp, "    Widths 4 index gget Scalew mul exch  %% str r c xcel ycel wcell bool\n");
  231.   fprintf (fp, "    { cell-goal-w sub 2 div 3 -1 roll add exch }\n");
  232.   fprintf (fp, "    { 2 index add cell-goal-w sub 3 -1 roll pop exch } ifelse \n");
  233.   fprintf (fp, "    %% str r c xstr ycel \n");
  234.   fprintf (fp, " } ifelse      \n");
  235.   fprintf (fp, " %% str r c xstr ycel \n");
  236.   fprintf (fp, " 5 -3 roll pop pop pop\n");
  237.   fprintf (fp, " 2 copy  cell-goal-h add exch cell-goal-w add exch\n");
  238.   fprintf (fp, " 4 array astore  \n");
  239.   fprintf (fp, "} def\n");
  240.   fprintf (fp, "\n");
  241.   fprintf (fp, "/layout        %%  [x y x' y'] r c -- [rlo clo rhi chi]\n");
  242.   fprintf (fp, "{\n");
  243.   fprintf (fp, "  2 copy \n");
  244.   fprintf (fp, "  /layout_c fed\n");
  245.   fprintf (fp, "  /layout_r fed\n");
  246.   fprintf (fp, "  exch 2 copy 4 array astore     %% [x y x' y'] [c r c r]\n");
  247.   fprintf (fp, "  /layout_answer fed\n");
  248.   fprintf (fp, "  /layout_goal fed\n");
  249.   fprintf (fp, "\n");
  250.   fprintf (fp, "  layout_answer 0 gget    \n");
  251.   fprintf (fp, "  {\n");
  252.   fprintf (fp, "    dup 0 eq { exit } if\n");
  253.   fprintf (fp, "    dup Colx exch gget Scalew mul layout_goal 0 gget le { exit } if\n");
  254.   fprintf (fp, "    1 sub\n");
  255.   fprintf (fp, "  } loop\n");
  256.   fprintf (fp, "  layout_answer exch 0 exch put\n");
  257.   fprintf (fp, "\n");
  258.   fprintf (fp, "  layout_answer 1 gget    \n");
  259.   fprintf (fp, "  {\n");
  260.   fprintf (fp, "    dup 0 eq { exit } if\n");
  261.   fprintf (fp, "    dup Rowy exch gget Scaleh mul layout_goal 1 gget le { exit } if\n");
  262.   fprintf (fp, "    1 sub\n");
  263.   fprintf (fp, "  } loop\n");
  264.   fprintf (fp, "  layout_answer exch 3 exch put\n");
  265.   fprintf (fp, "\n");
  266.   fprintf (fp, "  layout_answer 2 gget    \n");
  267.   fprintf (fp, "  {\n");
  268.   fprintf (fp, "    dup Cols 1 sub eq { exit } if\n");
  269.   fprintf (fp, "    dup dup Colx exch gget exch Widths exch gget add Scalew mul\n");
  270.   fprintf (fp, "    layout_goal 2 gget gt { exit } if\n");
  271.   fprintf (fp, "    1 add \n");
  272.   fprintf (fp, "  } loop\n");
  273.   fprintf (fp, "  layout_answer exch 2 exch put\n");
  274.   fprintf (fp, "\n");
  275.   fprintf (fp, "  layout_answer dup 0 gget exch 1 gget \n");
  276.   fprintf (fp, "  layout_answer exch 0 exch put layout_answer exch 1 exch put\n");
  277.   fprintf (fp, "  layout_answer dup 2 gget exch 3 gget \n");
  278.   fprintf (fp, "  layout_answer exch 2 exch put layout_answer exch 3 exch put\n");
  279.   fprintf (fp, "  layout_answer 1 gget 1 layout_answer 3 gget\n");
  280.   fprintf (fp, "  {\n");
  281.   fprintf (fp, "    /layout_ct fed\n");
  282.   fprintf (fp, "    layout_r 1 layout_answer 2 gget \n");
  283.   fprintf (fp, "     {\n");
  284.   fprintf (fp, "       /layout_rt fed\n");
  285.   fprintf (fp, "       layout_rt layout_ct checkused \n");
  286.   fprintf (fp, "    {\n");
  287.   fprintf (fp, "      layout_ct layout_c lt\n");
  288.   fprintf (fp, "        { layout_ct 1 add layout_answer 1 gget max layout_answer exch 1 exch put }\n");
  289.   fprintf (fp, "        if\n");
  290.   fprintf (fp, "      layout_ct layout_c gt\n");
  291.   fprintf (fp, "        { layout_ct 1 sub layout_answer 3 gget min layout_answer exch 3 exch put }\n");
  292.   fprintf (fp, "        if\n");
  293.   fprintf (fp, "      layout_rt layout_r lt\n");
  294.   fprintf (fp, "        { layout_rt 1 add layout_answer 0 gget max layout_answer exch 0 exch put }\n");
  295.   fprintf (fp, "        if\n");
  296.   fprintf (fp, "    } if\n");
  297.   fprintf (fp, "     } for\n");
  298.   fprintf (fp, "  } for\n");
  299.   fprintf (fp, "\n");
  300.   fprintf (fp, "  layout_answer 0 gget 1 layout_answer 2 gget \n");
  301.   fprintf (fp, "  {\n");
  302.   fprintf (fp, "    /layout_rt fed\n");
  303.   fprintf (fp, "    layout_answer 1 gget 1 layout_answer 3 gget\n");
  304.   fprintf (fp, "    {\n");
  305.   fprintf (fp, "      layout_rt exch setused\n");
  306.   fprintf (fp, "    } for \n");
  307.   fprintf (fp, "  } for\n");
  308.   fprintf (fp, "\n");
  309.   fprintf (fp, "  layout_answer\n");
  310.   fprintf (fp, "} def\n");
  311.   fprintf (fp, "\n");
  312.   fprintf (fp, "\n");
  313.   fprintf (fp, "/add-pair\n");
  314.   fprintf (fp, "{\n");
  315.   fprintf (fp, "  3 -1 roll add 3 1 roll add exch\n");
  316.   fprintf (fp, "} def\n");
  317.   fprintf (fp, "\n");
  318.   fprintf (fp, "/layout-to-oleo-box\n");
  319.   fprintf (fp, "{\n");
  320.   fprintf (fp, "  dup dup 0 gget exch 1 gget rc-to-oleo-xy 3 -1 roll\n");
  321.   fprintf (fp, "  dup 0 gget exch 1 gget \n");
  322.   fprintf (fp, "  2 copy rc-to-oleo-xy 4 2 roll\n");
  323.   fprintf (fp, "  rc-to-oleo-wh add-pair\n");
  324.   fprintf (fp, "  4 array astore\n");
  325.   fprintf (fp, "} def\n");
  326.   fprintf (fp, "\n");
  327.   fprintf (fp, "/layout-to-bbox\n");
  328.   fprintf (fp, "{\n");
  329.   fprintf (fp, "  layout-to-oleo-box oleo-box-to-ps\n");
  330.   fprintf (fp, "} def\n");
  331.   fprintf (fp, "\n");
  332.   fprintf (fp, "/boxpath\n");
  333.   fprintf (fp, "{\n");
  334.   fprintf (fp, "  newpath\n");
  335.   fprintf (fp, "  dup dup 0 gget exch 1 gget moveto\n");
  336.   fprintf (fp, "  dup dup 0 gget exch 3 gget lineto\n");
  337.   fprintf (fp, "  dup dup 2 gget exch 3 gget lineto\n");
  338.   fprintf (fp, "  dup 2 gget exch 1 gget lineto\n");
  339.   fprintf (fp, "  closepath\n");
  340.   fprintf (fp, "} def\n");
  341.   fprintf (fp, "\n");
  342.   fprintf (fp, "/use-font\n");
  343.   fprintf (fp, "{\n");
  344.   fprintf (fp, "  /CellFont fed\n");
  345.   fprintf (fp, "  CellFont setfont\n");
  346.   fprintf (fp, "  CellFont /FontBBox get\n");
  347.   fprintf (fp, "   dup dup 0 gget exch 1 gget CellFont /FontMatrix get transform\n");
  348.   fprintf (fp, "  neg /CellFontDescent fed\n");
  349.   fprintf (fp, "  neg /CellFontLbearing fed\n");
  350.   fprintf (fp, "   3 gget 0 exch CellFont /FontMatrix get transform exch pop\n");
  351.   fprintf (fp, "  /CellFontAscent fed\n");
  352.   fprintf (fp, "} def\n");
  353.   fprintf (fp, "DefaultFont use-font\n");
  354.   fprintf (fp, "\n");
  355.   fprintf (fp, "/cell %% str just r c\n");
  356.   fprintf (fp, "{\n");
  357.   fprintf (fp, "  /cell-c fed\n");
  358.   fprintf (fp, "  /cell-r fed\n");
  359.   fprintf (fp, "  /cell-j fed\n");
  360.   fprintf (fp, "  /cell-s fed\n");
  361.   fprintf (fp, "  \n");
  362.   fprintf (fp, "  /cell-g cell-s cell-j cell-r cell-c cell-goal def\n");
  363.   fprintf (fp, "  /cell-l cell-g cell-r cell-c layout layout-to-bbox def\n");
  364.   fprintf (fp, "\n");
  365.   fprintf (fp, "  cell-g 0 get cell-g 1 get moveto\n");
  366.   fprintf (fp, "  CellFontLbearing\n");
  367.   fprintf (fp, "  CellFontAscent neg rmoveto\n");
  368.   fprintf (fp, "  cell-s show\n");
  369.   fprintf (fp, "} def\n");
  370.   fprintf (fp, "\n");
  371.   {
  372.     int ri, ci;
  373.     struct font_memo * last_font = default_font ();
  374.     for (ri = 0; ri < rows; ++ri)
  375.       for (ci = 0; ci < cols; ++ci)
  376.     {
  377.       struct cell_display * cd = dpy.cells + ri * cols + ci;
  378.       if (cd->unclipped)
  379.         {
  380.           fprintf (fp, "/S ");
  381.           put_ps_string (cd->unclipped, fp);
  382.           fprintf (fp, " def \nS ");
  383.           switch (cd->justification)
  384.         {
  385.         default:
  386.         case JST_LFT:
  387.           fprintf (fp, " -1 ");
  388.           break;
  389.         case JST_CNT:
  390.           fprintf (fp, " 0 ");
  391.           break;
  392.         case JST_RGT:
  393.           fprintf (fp, " 1 ");
  394.           break;
  395.         };
  396.  
  397.           {
  398.         struct font_memo * font = cd->font;
  399.         if (!font)
  400.           font = default_font ();
  401.         if (font != last_font)
  402.           {
  403.             fprintf (fp, "/%s findfont %f DefaultFontSize mul",
  404.                  font->names->ps_name, font->scale);
  405.             fprintf (fp, " scalefont use-font\n");
  406.             last_font = font;
  407.           }
  408.         fprintf (fp, "%d %d cell\n", ri, ci);
  409.           }
  410.         }
  411.     }
  412.   }
  413.   free_display (&dpy);
  414. }
  415.  
  416.  
  417.  
  418. /* Front end to PostScript printing. */
  419.  
  420. struct page_size 
  421. {
  422.     char *name;
  423.     float wid;
  424.     float hgt;
  425. };
  426.  
  427. static struct page_size size_table[] =
  428. {
  429.   { "letter",       612,  792     }, /* (8.5 x 11  in.)   */
  430.   { "landscape",    792,  612     }, /* (11 x 8.5  in.)   */
  431.   { "tabloid",      792,  1224    }, /* (11 x 17  in.)    */
  432.   { "ledger",       1224, 792     }, /* (17 x 11  in.)    */
  433.   { "legal",        612,  1008    }, /* (8.5 x 14  in.)   */
  434.   { "statement",    396,  612     }, /* (5.5 x 8.5 in.)   */
  435.   { "executive",    540,  720     }, /* (7.5 x 10  in.)   */
  436.   { "a3",           842,  1190    },
  437.   { "a4",           595,  842     },
  438.   { "latex-a4",     523,  770     }, /* A4 - 1in margins all round */
  439.   { "a5",           420,  595     },
  440.   { "b4",           729,  1032    },
  441.   { "b5",           516,  729     },      
  442.   { "folio",        612,  936     }, /* (8.5 x 13  in.)   */
  443.   { "quarto",       610,  780     }
  444. };
  445.  
  446. #ifdef __STDC__
  447. static struct page_size *
  448. find_size( char * size, int len )
  449. #else
  450. static struct page_size *
  451. find_size( size, len )
  452.      char *size;
  453.      int len;
  454. #endif
  455. {
  456.   int i;
  457.   struct page_size *p = size_table;
  458.   
  459.   for (i = 0;
  460.        i < sizeof(size_table)/sizeof(struct page_size);
  461.        i++, p++)
  462.     if (strincmp (size, p->name, len) == 0 )
  463.       return p;
  464.   return 0;
  465. }
  466.  
  467. static float default_pswid = 8.5 * 72.;
  468. static float default_pshgt = 11. * 72.;
  469.  
  470. #ifdef __STDC__
  471. void
  472. set_page_size_cmd (char * whole_str)
  473. #else
  474. void
  475. set_page_size_cmd (whole_str)
  476.      char * whole_str;
  477. #endif
  478. {
  479.   char * str = whole_str;
  480.   float neww;
  481.   float newh;
  482.   while (*str && isspace(*str))
  483.     ++str;
  484.   if (!isdigit (*str) && *str != '.')
  485.     {
  486.       char * end = str;
  487.       struct page_size * ps;
  488.       while (*end && !isspace(*end))
  489.     ++end;
  490.       ps = find_size (str, end - str);
  491.       if (ps)
  492.     {
  493.       default_pswid = ps->wid;
  494.       default_pshgt = ps->hgt;
  495.       return;
  496.     }
  497.       io_error_msg
  498.     ("Bad page size (should look like `8.5 x 11' or `21.6 x 28c'): %s.",
  499.      whole_str);
  500.       return;
  501.     }
  502.   neww = atof (str);
  503.   while (*str && isdigit(*str))
  504.     ++str;
  505.   if (*str == '.')
  506.     {
  507.       ++str;
  508.       while (isdigit (*str))
  509.     ++str;
  510.     }
  511.   while (*str && isspace(*str))
  512.     ++str;
  513.   if (*str == 'x')
  514.     {
  515.       ++str;
  516.       while (*str && isspace(*str))
  517.     ++str;
  518.     }
  519.   if (!isdigit (*str) && *str != '.')
  520.     {
  521.       io_error_msg
  522.     ("Bad page size (should look like `8.5 x 11' or `21.6 x 28c'): %s.",
  523.      whole_str);
  524.       return;
  525.     }
  526.   newh = atof (str);
  527.   while (*str && isdigit(*str))
  528.     ++str;
  529.   if (*str == '.')
  530.     {
  531.       ++str;
  532.       while (*str && isdigit (*str))
  533.     ++str;
  534.     }
  535.   while (*str && isspace(*str))
  536.     ++str;
  537.   if (*str == 'c')
  538.     {
  539.       neww *= .3937;
  540.       newh *= .3937;
  541.     }
  542.   if (*str != 'p')
  543.     {
  544.       default_pswid = neww * 72;
  545.       default_pshgt = newh * 72;
  546.     }
  547. }
  548.  
  549. #ifdef __STDC__
  550. void 
  551. psprint_region_cmd (struct rng *rng, FILE *fp)
  552. #else
  553. void 
  554. psprint_region_cmd (rng, fp)
  555.      struct rng *rng;
  556.      FILE *fp;
  557. #endif
  558. {
  559.   psprint_region (fp, rng, default_pswid, default_pshgt, 0);
  560. }
  561.  
  562.  
  563.